package com.wbdgj.ui;

import android.view.View;
import android.widget.TextView;

import com.wbdgj.R;
import com.wbdgj.base.BaseActivity;
import com.wbdgj.base.BaseApplication;
import com.wbdgj.base.BaseWhiteActivity;
import com.wbdgj.ui.home.ExampleActivity;
import com.wbdgj.ui.login.LoginActivity;
import com.wbdgj.utils.SpKeyUtils;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by Administrator on 2016/11/22.
 *
 * @author yysleep
 */

public class PushActivity extends BaseWhiteActivity {
    @BindView(R.id.push_time_tv)
    TextView tvTime;
    int time = 1;
    final int totalCount = 3;
    boolean skiped;



    @Override
    protected void initView() {
//        tvTime.setText(String.valueOf(String.valueOf(totalCount)));
//        startCount();
        next();
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_push;
    }


    private void startCount() {
        getWindow().getDecorView().postDelayed(runnable, 1000);
    }

    @OnClick(R.id.ui_push_skip)
    public void onClick(View view) {
        skiped = true;
        next();
    }

    private Runnable runnable = new Runnable() {
        @Override
        public void run() {
            if (skiped)
                return;
            tvTime.setText(String.valueOf(String.valueOf(totalCount - time)));
            time++;
            if (time > totalCount) {
                next();
            } else {
                startCount();
            }
        }
    };

    private void next() {
        if (BaseApplication.getInstance().isGGFirstEnter()){
            launch(WelcomeActivity.class);
            finish();
        }else{
            if (BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.IS_AUTO_LOGIN).equals("1")) {
                launch(MainActivity.class);
            } else {
                launch(LoginActivity.class);
            }
            finish();
        }

    }


}
